<%@page import="cn.edu.nju.ws.sview.views.Group"%>
<%@page import="cn.edu.nju.ws.sview.views.User"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Group Detail</title>
	<link rel="icon" href="/sview/favicon.ico" />
	<link rel="stylesheet" type="text/css" href="/sview/css/group/group.css">
	<link rel="stylesheet" type="text/css" href="/sview/css/layout.css">
	<script type="text/javascript" src="/sview/script/jquery.js"></script>
	<script type="text/javascript" src="/sview/script/global.js"></script>
	<script type="text/javascript" src="/sview/script/group/gdetail.js"></script>
  </head>
  <%
  	String lang = request.getParameter("lang");
       if (lang != null && lang.equals("zh")) {
			request.getRequestDispatcher("gdetail_zh.jsp").forward(
					request, response);
		} else if (lang == null) {
			lang = "en";
		}
       String from = request.getParameter("from");
       
    	String uname = (String) session.getAttribute("user"); 
    	
    	int gid=-1;
    	
    	if(uname == null|| request.getParameter("gid")==null){
    		response.sendRedirect("/sview/views/index.jsp");
    	}else{
    		User user = new User(uname);
	    	gid = Integer.valueOf(request.getParameter("gid"));
	    	if(!Group.isMember(gid, User.getUserIdByName(uname))){
	    		response.sendRedirect("/sview/group/gmanage.jsp");
     		}
	    	
	    	String gname = Group.getGroupNameById(gid);
	    	ArrayList<String> memNames = Group.getMembers(gid);
	    	String admin = Group.getAdmin(gid);
	    	boolean isAdmin = uname.contentEquals(admin);
  %>
  <body>
   <jsp:include page="/vheader.jsp" flush="true" />
    <div id="container" class="container">
	    <div class="gHeader"><span class="large">Group Manage</span></div>
	    <div id="gmanage_ection" class="section">
	    	<p class="title" id="gname"><b><%=gname %></b> Group:</p>
			<p class="text" style="margin-left: 10px;">Admin: <%=admin %></p>
		    <div class="tabDiv">
		    	<ul class="tabUl">
		    		<li id="memberList" class="tabLi highlighted" onClick="clickTab();">Member List</li>
		    		<li id="viewList" class="tabLi faded" onClick="clickTab();">View List</li>
		    		<li id="entityList" class="tabLi faded" onClick="clickTab();">Entity List</li>
		    		<li id="datasetList" class="tabLi faded" onClick="clickTab();">Dataset List</li>
		    		<li id="relationList" class="tabLi faded" onClick="clickTab();">Relation List</li>
		    	</ul>
		    </div>
	    	<div class="content">
				<%if(memNames != null && memNames.size()>0){ %>
				<div class="memberList tableDiv" id="memberList">
				<table>
		    	<thead>
		    		<tr>
		    			<%if(isAdmin){ %>
		    			<td>Select</td>
		    			<%} %>
		    			<td>User Name</td>
		    			<td>Email</td>
		    		</tr>
		    	</thead>
		    	<tbody>
		    	<%for(String m : memNames){ 
					String email = new User(m).getEmail();
					%>
					<tr>
					<%if(isAdmin){ %>
		    			<td><input type="checkbox" class="checkbox" id=<%=m %>/></td>
		    			<%} %>
		    			<td><%=m %></td>
		    			<td><%=email %></td>
					</tr>
				<%} %>
		    	</tbody>
		    	</table>
		    	<%if(isAdmin){ %>
		    		<input type="button" class="form-button-little" id="delMem" value="Delete Member" style="float:right; margin-top:50px;" onClick="delMem();" />
		    		<input type="button" class="form-button-little" id="addMem" value="Add Member" style="float:right; margin-top:50px;" onClick="addMem();" />
		    		<%} %>
				</div>
				<%} %>
				<div class="tableDiv viewList" id="viewList" style="display: none;">
				<table>
			    	<thead>
			    		<tr>
			    			<td>View Name</td>
			    			<td>Use Times</td>
			    		</tr>
			    	</thead>
			    	<tbody>
			    	</tbody>
			    </table>
				</div>
				<div class="entityList tableDiv" id="entityList" style="display: none;">
					<table>
						<thead>
				    		<tr>
				    			<td>Entity Name</td>
				    		</tr>
				    	</thead>
				    	<tbody>
				    	</tbody>
			    	</table>
				</div>
				<div class="datasetList tableDiv" id="datasetList" style="display: none;">
					<table>
						<thead>
				    		<tr>
				    			<td>Dataset Name</td>
				    			<td>Create Time</td>
				    		</tr>
				    	</thead>
				    	<tbody>
				    	</tbody>
			    	</table>
				</div>
				<div class="relationList tableDiv" id="relationList" style="display: none;">
					<table>
						<thead>
				    		<tr>
				    			<td>Relation Name</td>
				    			<td>Create Time</td>
				    		</tr>
				    	</thead>
				    	<tbody>
				    	</tbody>
			    	</table>
				</div>
			</div>
	    </div>
    </div>
		<input type="hidden" id="display-lang" value="en" />
		<input type="hidden" id="gid" value="<%=gid %>" />
	<jsp:include page="/vfooter.jsp"></jsp:include>
  </body>
  <%} %>
</html>
